/*
 * @FileName: loop.c
 * @Author: GreyQiu qiushaogui@aikosolar.com
 * @Date: 2023-07-12 16:05:59
 * @LastEditors: GreyQiu qiushaogui@aikosolar.com
 * @LastEditTime: 2023-08-16 18:08:51
 * @Description: 
 * 
 * Copyright (c) 2023, All Rights Reserved. 
 */

#include "loop.h"
#include "bsp_pwm.h"

#define CONTROL_FREQ    (PWM_FREQ / 2)

boost_controller_t controller[BOOST_NUM];

void loop_init(void)
{
    for (uint16_t id = 0; id < BOOST_NUM; id++) {
        controller[id].vin.Ymax = 15.0f;
        controller[id].vin.Ymin = 0.0f;
        easy_pid_config(&controller[id].vin, CONTROL_FREQ, -0.125f, -125.0f, 0);

        controller[id].current.Ymax = 45.0f;
        controller[id].current.Ymin = 0.0f;
        easy_pid_config(&controller[id].current, CONTROL_FREQ, 0.33f, 1000.0f, 0);

        controller[id].vout.Ymax = 45.0f;
        controller[id].vout.Ymin = 0.0f;
        easy_pid_config(&controller[id].vout, CONTROL_FREQ, 0.1f, 300.0f, 0);

        controller[id].vin.ref = 54.0f;
        controller[id].current.ref = 0.0f;
        controller[id].vout.ref = 0.0f;
    }
}
